//
//  NSString+JJ.h
//  JJObjCTool
//
//  Created by hamilyjing on 5/11/15.
//  Copyright (c) 2015 gongjian. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface NSString (JJ)

#pragma mark - mask code 掩码

+ (NSString *)maskCode:(NSString *)name;

#pragma mark - Data

- (NSData *)jj_data;

#pragma mark - UI

- (CGSize)jj_textSize:(UIFont *)font;

#pragma mark - Remove characters

- (NSString *)jj_trimWhitespace; // 删除两边空格
- (NSString *)jj_trimNewline; // 删除回车
- (NSString *)jj_trimWhitespaceAndNewline; // 删除两边空格和回车

#pragma mark - UUID

+ (NSString *)jj_UUID;

#pragma mark - MD5

- (NSString *)jj_md5String;
- (NSData *)jj_md5Data;

#pragma mark - Base64

- (NSString *)jj_base64EncodedString;
- (NSData *)jj_base64EncodedData;
- (NSString *)jj_base64DecodedString;
- (NSData *)jj_base64DecodedData;

#pragma mark - JSON

- (NSDictionary *)jj_dictionaryWithJSON;

+ (id)jj_convertToStrictDictionaryWithJSONStringWithOtherInfo:(id)otherInfo;
+ (id)jj_convertToStrictDictionaryWithJSONStringWithOtherInfo:(id)otherInfo callback:(void(^)(NSDictionary *responseDict, id bodyDict))callback;
+ (NSString *)jj_stringByRemovingCharactersInSet:(NSCharacterSet*) charsToRemove withString:(NSString *)str;

#pragma mark - URL

- (NSString*)jj_urlEncodedString;
- (NSString*)jj_urlDecodedString;

- (NSString *)jj_urlEncodeUsingEncoding:(CFStringEncoding)encoding;
- (NSString *)jj_urlDecodeUsingEncoding:(CFStringEncoding)encoding;

// http://www.example.com/index.php?key1=value1&key2=value2 , the query string is key1=value1&key2=value2. Self is "key1=value1&key2=value2"
- (NSDictionary *)jj_dictionaryWithURLQuery;

#pragma mark - SubString

- (BOOL)jj_containsString:(NSString *)string;
- (BOOL)jj_containsString:(NSString *)string
                  options:(NSStringCompareOptions)options;

- (NSString *)jj_subStringBeforeFirstSeparator:(NSString *)separator;
- (NSString *)jj_subStringAfterFirstSeparator:(NSString *)separator;

- (NSArray *)jj_stringBetweenTheSameString:(NSString *)separator;


#pragma mark - remove NSString_extra to here TODO:lynn

+ (NSString *)MD5StringFrom:(NSString*)source;
- (NSString *)URLEncodedString;
- (NSString *)URLDecodedString;
+ (NSString *)normaPhoneNumber:(NSString *)number;//电话号码去掉多余的字符
- (NSRange)composedRangeWithRange:(NSRange)range;//处理Emoji表情取长度问题
- (NSString *)composedSubstringWithRange:(NSRange)range;
- (NSString *)composedStringFromIndex:(int)index;
- (NSString *)composedStringToIndex:(int)index;
+(BOOL)isContainsEmoji:(NSString *)string;
-(NSString *)milliSecondString2Second;
- (NSData*) dataFromHex;
- (NSString *)stringByReversed;

#pragma mark - remove NSString_CMUtils to here TODO:yinxukun

+ (BOOL)jj_isBlank:(NSString *)str;
+ (BOOL)jj_isEmpty:(NSString *)str;
+ (NSString *)jj_emptyOrString:(NSString *)str;
+ (NSString *)jj_emptyOrStringAndTrim:(NSString *)str;
+ (NSString *)jj_defaultValue:(NSString *)defaultStr OrString:(NSString *)str;
- (NSString *)jj_base64String;


#pragma mark - remove NSString_objectFromJSONString to here TODO:yinxukun 

- (id)jj_objectFromJSONString;
+ (NSString *)jj_noNilString:(NSString *)str;

// 手机号格式化（3 4 4）
+ (NSString *)jj_phoneNumberFormat:(NSString *)phoneNumber;
// 判断字符串是否手机号
- (BOOL)jj_isPhoneNumber;

// 判断字符串是否email
- (BOOL)jj_isEmail;

// 校正手机号：如去掉前面的86，17951等，并且只取11位
- (NSString *)jj_adjustedPhoneNumber;

+ (NSString *)jj_updateRequestInfo:(NSArray *)arr;

// 只保留数字和小数点
- (NSString *)jj_numFromString;

#pragma mark - JSONString、NSDictionary、NSArray
+ (NSString *)jj_dictionaryToJSONString:(NSDictionary *)dictionary;
+ (NSDictionary *)jj_dictionaryFromJSONString:(NSString *)jsonString;
+ (NSString *)jj_arrayToJSONString:(NSArray *)array;
+ (NSArray *)jj_arrayFromJSONString:(NSString *)jsonString;

@end
